import httop from "./index";
import { LOGIN, PASSWORD, ROLE, CUSTOM ,CONTRACT,CUSTOMDATA,CONTRACTAMOUNT,RECEIVEAMOUNT,FINALAMOUNT ,INDUSTRYDATA ,GETALLCONTRACT} from "./path";


import type { IParms } from "../type/types";
import type { AxiosResponse } from "axios";


interface ILoginForm {
  username: string;
  password: string;
}

interface IRes {
  data: {
    msg: string;
    code: number;
  };
}

interface IPAsswordForm {
  password: string;
  newpassword: string;
  repassword: string;
}
interface IGetRes<T> {
  data: {
    msg: string;
    code: number;
    row: T[];
    count: number;
  };
}
interface IRoledata {
  
    id: number;
    name: string;
    create_time: string;
    auth: number;
  
}
interface ICustomData {
  id: number;
  company: string;
  industary: string;
  province: string;
  name: string;
  phone: string;
  title: string;
  status: string;
  needs: string;
}
interface ICustom<T> {
  data: {
    msg: string;
    code: number;
    row: T[];
    count: number;
  };
}

interface IContract<T>{
    data:{
      msg: string;
    code: number;
    row: T[];
    count: number;
    }
}
interface IContractForm{
  number:number,
    name:string,
    industry:string,
    undertaking_department:string,
    service_company:string,
    sign_people:string,
    handle_people:string,
    sign_data:string,
    contract_type:string,
    contract_status:string,
    service_term:string,
    contract_money:number,
    pay_type:string,
    start_data:string,
    end_data:string
}


export function login(body: ILoginForm): Promise<AxiosResponse<IRes>> {
  return httop.post(LOGIN, body);
}
export function password(body: IPAsswordForm): Promise<AxiosResponse<IRes>> {
  return httop.post(PASSWORD, body);
}
export function getRole(query: IParms): Promise< AxiosResponse<IGetRes<{ id: number; name: string; create_time: string; auth: number }>>> {return httop.get(ROLE, query);
}
export function addRole(body: {
  name: string;
  auth: number;
}): Promise<AxiosResponse<IRes>> {
  return httop.post(ROLE, body);
}
export function deleteRole(id: number): Promise<AxiosResponse<IRes>> {
  return httop.delete(ROLE + "/" + id);
}
export function getOneRole(id: number): Promise<AxiosResponse<{ data: IRoledata }>> {
  return httop.getone(ROLE + "/" + id);
}
export function upData(body: IRoledata, id: number) {
  return httop.put(ROLE + "/" + id, body);
}
export function getCustom(body: IParms): Promise<AxiosResponse<ICustom<ICustomData>>> {
  return httop.get(CUSTOM, body);
}

export function addCustom(body: ICustomData): Promise<AxiosResponse<IRes>> {
  return httop.post(CUSTOM, body);
}
export function getoneCustom(id:number):Promise<AxiosResponse<{data:ICustomData}>>{
  return httop.getone(CUSTOM+"/"+id)
}
export function editCustom(body: ICustomData,id:number): Promise<AxiosResponse<IRes>>{
  return httop.put(CUSTOM+"/"+id,body)
}
export function deleteCustom(id: number): Promise<AxiosResponse<IRes>> {
  return httop.delete(CUSTOM + "/" + id);
}


//合同
export function getContract(body:IParms):Promise<AxiosResponse<IContract<IContractForm>>>{
  return httop.get(CONTRACT,body)
}
export function addContract(body: IContractForm): Promise<AxiosResponse<IRes>> {
  return httop.post(CONTRACT, body);
}
export function getoneContract(id:number):Promise<AxiosResponse<{data:IContractForm}>>{
  return httop.getone(CONTRACT+"/"+id)
}
export function editContract(body: IContractForm,id:number): Promise<AxiosResponse<IRes>>{
  return httop.put(CONTRACT+"/"+id,body)
}
export function deleteContract(id: number): Promise<AxiosResponse<IRes>> {
  return httop.delete(CONTRACT + "/" + id);}

  //数据分析
  interface IDatacountParms {
    year:string 
  }
  interface ICount{
    data: {
      msg: string;
      code: number;
      count:number;
    };
  }
  //获取客户数据
  export function getcustomData(query:IDatacountParms|any): Promise<AxiosResponse<ICount>>{
    return httop.get(CUSTOMDATA,query)
  }
 //获取合同金额
 export function getcontractAmunt(query:IDatacountParms|any): Promise<AxiosResponse<ICount>>{
  return httop.get(CONTRACTAMOUNT,query)
}
 //获取接收金额
 export function getreceiveAmount(query:IDatacountParms|any): Promise<AxiosResponse<ICount>>{
  return httop.get(RECEIVEAMOUNT,query)
}
 //获取尾款金额
 export function getfinalAmount(query:IDatacountParms|any): Promise<AxiosResponse<ICount>>{
  return httop.get(FINALAMOUNT,query)
}

interface industryData{
   data:{
    msg:string,
    code:number,
    count:{industry:string,value:number}[],
   }
}
//各行业数据
export function getindustryData():Promise<AxiosResponse<industryData>>{
  return httop.get(INDUSTRYDATA,{})
}
interface allContractData{
  data:{
    msg:string,
    code:number,
    row:{year:string,contract_amount:number,receive_amount: number,final_amount: number,},
   }
}
//获取所有合同数据
export function getallContract(query:IDatacountParms|any):Promise<AxiosResponse<allContractData>>{
  return httop.get(GETALLCONTRACT,query)
}